﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace QD.Web.Upload
{
    public class FileUpload : Ajax.AjaxPage
    {
        protected UploadCfg GetUploadConfig(UploadType type)
        {
            this.moduleCode = base.Parse.Int("module");

            if (!this.moduleCode.HasValue)
            {
                throw new ArgumentNullException("ModuleCode missing");
            }
            if (type == UploadType.File)
            {
                return FileConfigs[this.moduleCode.Value];
            }
            return ImageConfigs[this.moduleCode.Value];
        }

        protected override void PageLoad()
        {
            if (base.Context.Request.Files.Count == 0)
            {
                throw new ArgumentNullException("FileData not found");
            }
            HttpPostedFile httpfile = base.Context.Request.Files[0];
            UploadCfg uploadConfig = this.GetUploadConfig(UploadType.File);
            if (Upload.UploadFile(httpfile, uploadConfig.FolderCfg).IsError)
            {
            }
        }

        public static void RegisterConfig(int moduleCode, UploadType type, UploadCfg config)
        {
            if (type == UploadType.File)
            {
                FileConfigs.Add(moduleCode, config);
            }
            else if (type == UploadType.Image)
            {
                ImageConfigs.Add(moduleCode, config);
            }
        }
        protected static IDictionary<int, UploadCfg> FileConfigs;
        protected static IDictionary<int, UploadCfg> ImageConfigs;

        protected int? moduleCode;
 

 



 

 


 


 

    }
}
